<template>
	<view class="page">
		<view v-if="!hasLogin">现在是未登录状态，点击按钮进行登录</view>
		<view v-else>现在是登录状态，您的用户id是：{{userInfo.userName}}</view>
		<button type="primary" @click="bindLogin">{{hasLogin ? '退出登录' : '登录'}}</button>
		<button @click="scanCode">打开扫描</button>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		computed: mapState(['hasLogin', 'userInfo']),
		methods: {
			...mapMutations(['logout']),
			bindLogin() {
				if (this.hasLogin) {
					this.logout()
				} else {
					uni.navigateTo({
						url: '/pages/main/login'
					})
				}
			},
			scanCode() {
				// 允许从相机和相册扫码
				uni.scanCode({
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
					}
				});
			}

		}
	}
</script>

<style>
</style>
